<#assign security=JspTaglibs["http://www.springframework.org/security/tags"] />
<!DOCTYPE html>
<html>
<head>
    <#include "../_template.ftl">
    <title>首页</title>
</head>
<body>
<div class="layui-fluid">
    <div class="layui-card">
        <div class="layui-form layui-card-header layuiadmin-card-header-auto">
            <div class="layui-form-item">
			                <div class="layui-inline">
                    <label class="layui-form-label">id：</label>
                    <div class="layui-input-inline">
                        <input type="text" name="id" placeholder="请输入id" autocomplete="off" class="layui-input">
                    </div>
                </div>
			                <div class="layui-inline">
                    <label class="layui-form-label">用户名：</label>
                    <div class="layui-input-inline">
                        <input type="text" name="username" placeholder="请输入用户名" autocomplete="off" class="layui-input">
                    </div>
                </div>
			                <div class="layui-inline">
                    <label class="layui-form-label">登录密码：</label>
                    <div class="layui-input-inline">
                        <input type="text" name="password" placeholder="请输入登录密码" autocomplete="off" class="layui-input">
                    </div>
                </div>
			                <div class="layui-inline">
                    <label class="layui-form-label">真实姓名：</label>
                    <div class="layui-input-inline">
                        <input type="text" name="realName" placeholder="请输入真实姓名" autocomplete="off" class="layui-input">
                    </div>
                </div>
			                <div class="layui-inline">
                    <label class="layui-form-label">电话：</label>
                    <div class="layui-input-inline">
                        <input type="text" name="phone" placeholder="请输入电话" autocomplete="off" class="layui-input">
                    </div>
                </div>
			                <div class="layui-inline">
                    <label class="layui-form-label">性别 1.男 0女：</label>
                    <div class="layui-input-inline">
                        <input type="text" name="gender" placeholder="请输入性别 1.男 0女" autocomplete="off" class="layui-input">
                    </div>
                </div>
			                <div class="layui-inline">
                    <label class="layui-form-label">头像：</label>
                    <div class="layui-input-inline">
                        <input type="text" name="avatarUrl" placeholder="请输入头像" autocomplete="off" class="layui-input">
                    </div>
                </div>
			                <div class="layui-inline">
                    <label class="layui-form-label">部门id：</label>
                    <div class="layui-input-inline">
                        <input type="text" name="deptId" placeholder="请输入部门id" autocomplete="off" class="layui-input">
                    </div>
                </div>
			                <div class="layui-inline">
                    <label class="layui-form-label">角色id：</label>
                    <div class="layui-input-inline">
                        <input type="text" name="roleId" placeholder="请输入角色id" autocomplete="off" class="layui-input">
                    </div>
                </div>
			                <div class="layui-inline">
                    <label class="layui-form-label">状态：</label>
                    <div class="layui-input-inline">
                        <input type="text" name="state" placeholder="请输入状态" autocomplete="off" class="layui-input">
                    </div>
                </div>
			                <div class="layui-inline">
                    <label class="layui-form-label">创建时间：</label>
                    <div class="layui-input-inline">
                        <input type="text" name="createTime" placeholder="请输入创建时间" autocomplete="off" class="layui-input">
                    </div>
                </div>
			                <div class="layui-inline">
                    <label class="layui-form-label">修改时间：</label>
                    <div class="layui-input-inline">
                        <input type="text" name="updateTime" placeholder="请输入修改时间" autocomplete="off" class="layui-input">
                    </div>
                </div>
			                <div class="layui-inline">
                    <button class="layui-btn layuiadmin-btn-list" lay-submit lay-filter="sysUser-data-search">
                        <i class="layui-icon layui-icon-search layuiadmin-button-btn"></i>
                    </button>
                </div>
            </div>
        </div>

        <div class="layui-card-body">
            <div style="padding-bottom: 10px;">
            <@security.authorize access="hasAuthority('sysUser-delete')">
                <button class="layui-btn layuiadmin-btn-list" data-type="add"><i
                            class="layui-icon layui-icon-add-circle-fine"></i>添加
                </button>
            </@security.authorize>
            </div>
            <table class="layui-hide" id="data-sysUser" lay-filter="data-sysUser"></table>
        </div>
    </div>
</div>
<script>
    layui.config({
        base: '${request.contextPath}/layuiadmin/' //静态资源所在路径
    }).extend({
        index: 'lib/index' //主入口模块
    }).use(["index","table", "jquery", "form", "laydate", "upload"], function () {
        var table = layui.table
            , $ = layui.jquery
            , form = layui.form;
        NProgress.start()
        table.render({
            elem: '#data-sysUser'
            , url: '${request.contextPath}/sysUser/list'
            , page: true
            , limit: 10
            , height: 'full-180'
            , limits: [10, 20, 30, 50, 100]
            , cols: [[
                {type: 'numbers', fixed: 'left'}
				                , {field: 'id', title: 'id'}
				                , {field: 'username', title: '用户名'}
				                , {field: 'password', title: '登录密码'}
				                , {field: 'realName', title: '真实姓名'}
				                , {field: 'phone', title: '电话'}
				                , {field: 'gender', title: '性别 1.男 0女'}
				                , {field: 'avatarUrl', title: '头像'}
				                , {field: 'deptId', title: '部门id'}
				                , {field: 'roleId', title: '角色id'}
				                , {field: 'state', title: '状态'}
				                , {field: 'createTime', title: '创建时间'}
				                , {field: 'updateTime', title: '修改时间'}
				               
                , {fixed: 'right', title: '操作', align: 'center', width: 180, toolbar: '#bar'}
            ]]
            , done: function () {
                NProgress.done()
            }
        });

        //头工具栏事件
        form.on('submit(sysUser-data-search)', function (data) {
            table.reload('data-sysUser', {
                where: data.field
            });
        });

        var active = {
            add: function () {
                layer.open({
                    type: 2
                    , title: '添加用户'
                    , content: '${request.contextPath}/sysUser/add'
                    , maxmin: true
                    , area: ['550px', '550px']
                    , btn: ['确定', '取消']
                    , yes: function (index, layero) {
                        //点击确认触发 iframe 内容中的按钮提交
                        var submit = layero.find('iframe').contents().find("#sysUser-form-add");
                        submit.click();
                    }
                });
            }
        };
        $('.layui-btn.layuiadmin-btn-list').on('click', function () {
            var type = $(this).data('type');
            active[type] ? active[type].call(this) : '';
        });

        table.on('tool', function (obj) {
            var data = obj.data;
            if (obj.event === 'detail') {

            } else if (obj.event === 'delete') {
                layer.confirm('确定删除?', function () {
                    $.ajax({
                        url: "${request.contextPath}/sysUser/delete",
                        data: {"id": data.id},
                        type: "post",
                        dataType: "json",
                        success: function (m) {
                            if (m.code == 0) {
                                layer.msg(m.msg);
                                obj.del();
                            }
                        }
                    });
                });
            } else if (obj.event === 'edit') {
                layer.open({
                    type: 2
                    , title: '修改用户信息'
                    , content: '${request.contextPath}/sysUser/update'
                    , maxmin: true
                    , area: ['550px', '550px']
                    , btn: ['修改', '取消']
                    , yes: function (index, layero) {
                        //点击确认触发 iframe 内容中的按钮提交
                        var submit = layero.find('iframe').contents().find("#sysUser-form-update");
                        submit.click();
                    }
                });
            }
        });
    });
</script>

<script type="text/html" id="bar">
<@security.authorize access="hasAuthority('sysUser-update')">
    <a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
</@security.authorize>
<@security.authorize access="hasAuthority('sysUser-delete')">
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="delete">删除</a>
</@security.authorize>
</script>

</body>
</html>